package com.termux.utils

import android.app.Activity
import android.content.Context
import android.content.pm.PackageManager
import android.widget.Toast
import androidx.core.app.ActivityCompat.requestPermissions
import androidx.core.app.ActivityCompat.shouldShowRequestPermissionRationale
import androidx.core.content.ContextCompat.checkSelfPermission

object PermissionUtil {
    fun hasPermission(context: Context, permission: String): Boolean {
        return checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED;
    }

    fun applyPermission(activity: Activity, permission: String) {
        if (shouldShowRequestPermissionRationale(activity, permission)) {
            Toast.makeText(activity, "request read sdcard permission", Toast.LENGTH_SHORT).show();
        }
        requestPermissions(activity, arrayOf(permission), 0);
    }
}